<?php
/**
 * 高级查询所需的文档
 * Created by PhpStorm.
 * User: bimUser
 * Date: 2018/1/20
 * Time: 17:14
 */
require 'config.php';
require 'vendor/autoload.php';

// 实例化连接
$db = new MongoDB\Client("mongodb://{$cnf['USERNAME']}:{$cnf['PASSWD']}@{$cnf['HOST']}:{$cnf['PORT']}/{$cnf['DBNAME']}");

// 插入文档
$insertManyResult = $db->test->inventory->insertMany([
    [
        'item' => 'journal',
        'status' => 'A',
        'size' => ['h' => 14, 'w' => 21, 'uom' => 'cm'],
        'instock' => [
            ['warehouse' => 'A', 'qty' => 5],
        ],
    ],
    [
        'item' => 'notebook',
        'status' => 'A',
        'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
        'instock' => [
            ['warehouse' => 'C', 'qty' => 5],
        ],
    ],
    [
        'item' => 'paper',
        'status' => 'D',
        'size' => ['h' => 8.5, 'w' => 11, 'uom' => 'in'],
        'instock' => [
            ['warehouse' => 'A', 'qty' => 60],
        ],
    ],
    [
        'item' => 'planner',
        'status' => 'D',
        'size' => ['h' => 22.85, 'w' => 30, 'uom' => 'cm'],
        'instock' => [
            ['warehouse' => 'A', 'qty' => 40],
        ],
    ],
    [
        'item' => 'postcard',
        'status' => 'A',
        'size' => ['h' => 10, 'w' => 15.25, 'uom' => 'cm'],
        'instock' => [
            ['warehouse' => 'B', 'qty' => 15],
            ['warehouse' => 'C', 'qty' => 35],
        ],
    ],
]);
